import {
	PortalViewActionType,
	IPortalViewAbility,
	IParam,
	IPortalViewController,
	IDashboardAbility,
} from '@/core/interface';
import { IPortalViewStore } from '@/core/interface/view/store';
import { ViewController } from './view-controller';

/**
 * 应用看板视图控制器
 *
 * @export
 * @class PortalViewController
 * @extends {ViewController}
 */
export class PortalViewController
	extends ViewController<
		PortalViewActionType,
		IPortalViewStore,
		IPortalViewAbility
	>
	implements IPortalViewController<IPortalViewStore, IPortalViewAbility>
{
	/**
	 * 获取看板部件能力
	 *
	 * @protected
	 * @return {*}  {(IDashboardAbility | undefined)}
	 * @memberof PortalViewController
	 */
	protected getCtrlAbility(): IDashboardAbility | undefined {
		const dashboard = this.model.ctrls.find(
			(ctrl: IParam) => ctrl.controlType === 'DASHBOARD'
		);
		if (dashboard) {
			return this.getSubAbility<IDashboardAbility>(dashboard.name);
		}
		return undefined;
	}

	/**
	 * 视图加载
	 *
	 * @param {IParam} [opts={}]
	 * @return {*}
	 * @memberof PortalViewController
	 */
	public viewMounted(opts: IParam = {}) {
		super.viewMounted(opts);
		if (this.model.useDefaultLayout) {
			if (!this.isLoadDefault) {
				this.isLoadDefault = true;
				return;
			}
		} else {
			this.initLayout();
		}
	}
}
